#include <sys/mman.h>
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>

struct data
{
	int id;
	char name[128];
};


int main(int argc, char **argv)
{
	if(argc<=1)
	{
		printf("params error...\n");
		return 1;
	}

	int fd = open(argv[1], O_RDWR|O_CREAT, 00777);

	if(fd<0)
	{
		printf("open file error...");
		return 1;
	}

	struct data * p_data = (struct data*)mmap(NULL, 
											sizeof(struct data)*100, 
											PROT_READ|PROT_WRITE, 
											MAP_SHARED, 
											fd, 
											0);

	struct data *p_bak = p_data;

	printf("%p\n", p_data);
	int i;
	for(i=0;i<100;i++)
	{
		printf("name:%s \t id:%d\n", p_data->name, p_data->id);
		p_data++;
	}

	printf("read over\n");
	close(fd);

	munmap((void*)p_bak, sizeof(struct data)*100);

	return 0;
}
